﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SuperEnemy : Enemy {

    public Transform m_rocket;
    float m_fireTime = 2;
    Transform m_player;
	// Use this for initialization
	void Start () {
        renderer = GetComponent<Renderer>();
        // m_rocket = GameObject.FindGameObjectWithTag("EnemyRocket").transform;
        // m_explosionFX = base.m_explosionFX;

    }

    // Update is called once per frame
    void Update () {
        UpdateMove();
        if (m_isActive && !renderer.isVisible)
        {
            Destroy(gameObject);
        }

    }
    private void OnBecameVisible()
    {
        m_isActive = true;
    }
    protected override void UpdateMove()
    {
       // base.UpdateMove();
        m_fireTime -= Time.deltaTime;
        if (m_fireTime <= 0)
        {
            m_fireTime = 1;
            if (m_player != null)
            {
                Vector3 pos = m_player.position - transform.position;
                Instantiate(m_rocket, transform.position, Quaternion.LookRotation(pos));
            }
            else
            {
                GameObject obj = GameObject.FindGameObjectWithTag("Player");
                if (obj!=null)
                {
                    m_player = obj.transform;
                }
            }
        }

        transform.Translate(new Vector3(0, 0, -m_speed * Time.deltaTime));

    }

}
